#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include<queue>
using namespace std;
#define MAXL 40005
struct jd
{
	int v;
	int w;
};
int dp[MAXL];
bool vis[MAXL];
int n, m, u, v, w, d = 0;
vector<jd>a[MAXL];
void dfs(int u)
{
	vis[u] = 1;
	for (jd sv : a[u])
	{
		if (vis[sv.v])
			continue;
		dfs(sv.v);
		d = max(d, dp[u] + dp[v] + sv.w);
		dp[u] = max(dp[u], dp[v] + sv.w);
	}
}
int main()
{
	cin >> n >> m;
	char ch;
	for (int i = 0; i < m; i++)
	{
		cin >> u >> v >> w >> ch;
		a[u].push_back({ v,w });
		a[v].push_back({ u,w });
	}
	dfs(1);
	cout << d << endl;
	return 0;
}